/*
 * BootQuad_RemoteRes.java
 *
 * Created on December 3, 2005, 4:04 PM
 */

package aa.application.AdaptiveQuad;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import aa.core.Platform;
import aa.core.CyberOrg;
import aa.core.ActorName;
import aa.core.ActorMessage;
import aa.gui.View;


/**
 *
 * @author  xinghuizhao
 */
public class BootQuad_RemoteRes {
    
    /** Creates a new instance of BootQuad_RemoteRes */
    public BootQuad_RemoteRes() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
       
        
        System.out.println(System.currentTimeMillis());
        
        Integer myPort = new Integer(8070);
        
        
        //View myView = new View(myPort);
        
        //Platform pPlatform=new Platform(myView,myPort);
        
        Platform pPlatform = new Platform(null,myPort);
        
        pPlatform.start();
        
        Object[] nullobja={};
        
        CyberOrg fibCyber=(CyberOrg)pPlatform.createCyberOrg(new Long(90000000), new Long(900000), new Long(1000),"aa.application.AdaptiveQuad.QuadFacilitator", nullobja);
        
        CyberOrg fibCyber2=(CyberOrg)pPlatform.createCyberOrg(new Long(90000000), new Long(900000), new Long(1000),"aa.application.AdaptiveQuad.QuadFacilitator", nullobja);
        
        //pPlatform.createActor(fibCyber2.getFacilitator(),"aa.application.AdaptiveQuad.YellowPageActor",nullobja);
        
        pPlatform.removeCyberOrg(fibCyber2);
        
        //System.out.println(fibCyber2.getFacilitator());
        
        ActorName facility=fibCyber.getFacilitator();
        
        
        
        ActorName fibonacciActor=null;
        
        System.out.print("Please input the IP address of the destination node: ");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String remoteDesti=null;
        try{
        		remoteDesti = br.readLine();
        } catch (IOException ioe){
        		System.out.println("IO error trying to read the Destination Address!");
        		System.exit(1);
        }
        
        Object[] quadAgs = {new Double(0.001),facility,remoteDesti};
        
        
        ActorName quadActor=pPlatform.createActor(facility, "aa.application.AdaptiveQuad.QuadActor_RemoteRes", quadAgs);
        
        
        //adapt for QuadActor (in order to allocate resource)
        
        Object[] quadAgs2 = {new Double(0.001),quadActor,facility,remoteDesti};
        
        //Object[] quadAgs2 = {new Double(0.1),quadActor,facility,new ActorName("128.233.109.164",2)};
        
        ActorName quadActor2=pPlatform.createActor(facility, "aa.application.AdaptiveQuad.QuadActor_RemoteRes", quadAgs2);
        
        //end adapt
        
        Object[] Ags=new Object[4];
        Ags[0] = new Double(0);
        Ags[1] = new Double(1);
        Ags[2] = quadActor2;
        Ags[3] = "result";
        
        ActorMessage request=new ActorMessage(pPlatform.getActorNameOfPlatform(), 
                                                quadActor2, "quadrature",Ags, false);
        
        
        
        
        pPlatform.sendMessage(request);
        
        
    
    
    }
    
}
